package com.qf.rabbitmqspringboot.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 死信队列配置
 * @author zjw
 */
@Configuration
public class DeadLetterConfig {

    public static final String NORMAL_EXCHANGE = "normal_exchange";
    public static final String NORMAL_QUEUE = "normal_queue";


    public static final String DEAD_EXCHANGE = "dead_exchange";
    public static final String DEAD_QUEUE = "dead_queue";

    @Bean
    public Exchange normalExchange(){
        return ExchangeBuilder.fanoutExchange(NORMAL_EXCHANGE).build();
    }
    @Bean
    public Queue normalQueue(){
        return QueueBuilder.durable(NORMAL_QUEUE).withArgument("x-dead-letter-exchange",DEAD_EXCHANGE).build();
    }
    @Bean
    public Binding normalBinding(Queue normalQueue,Exchange normalExchange){
        return BindingBuilder.bind(normalQueue).to(normalExchange).with("").noargs();
    }
    //=====================================================================


    @Bean
    public Exchange deadExchange(){
        return ExchangeBuilder.fanoutExchange(DEAD_EXCHANGE).build();
    }
    @Bean
    public Queue deadQueue(){
        return QueueBuilder.durable(DEAD_QUEUE).build();
    }
    @Bean
    public Binding deadBinding(Queue deadQueue,Exchange deadExchange){
        return BindingBuilder.bind(deadQueue).to(deadExchange).with("").noargs();
    }
}
